package com.ybxx.config.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;

import com.ybxx.config.model.HouseType;
import com.ybxx.config.service.HouseTypeService;
import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.util.UUIDGenerator;
import com.ybxx.core.web.action.BaseAction;

public class HouseTypeAction extends BaseAction {
	@Resource
	private HouseTypeService houseTypeService;
	private HouseType houseType;
	private List<HouseType> houseTypes;
	private String msg="succ";
	/*删除*/
	public String remove(){
		try{
			houseTypeService.remove(houseType.getHcode());
		}catch(Exception ex){
			msg="户型删除失败";
		}finally{
			return "succ";
		}
	}
	/*加载查看时候需要展示的数据*/
	public String view(){
		if(houseType!=null && StringUtils.isNotEmpty(houseType.getHcode())){
			houseType=houseTypeService.get(houseType.getHcode());
		}
		return "view";
	}
	public String queryPage(){
		QueryFilter filter=new QueryFilter(getRequest());
		houseTypes=houseTypeService.queryPage(houseType,filter);
		super.setRownum(filter.getPagingBean().getTotalItems());
		super.setCurrentpage(Integer.parseInt(filter.getPagingBean().getStart()+"")/Integer.parseInt(filter.getPagingBean().getPageSize()+"")+1);
		super.setPageSize(Integer.parseInt(filter.getPagingBean().getPageSize()+""));
		return "queryPage";
	}
	/*保存新增，修改信息*/
	public String save(){
		if(StringUtils.isEmpty(houseType.getHcode())){
			houseType.setHcode(UUIDGenerator.getUUID());
		}
		try{
			houseTypeService.save(houseType);
		}catch(Exception ex){
			msg="户型信息保存失败.";
		}finally{
			return "succ";
		}
	}
	/*加载修改时候需要展示的数据*/
	public String load(){
		if(houseType!=null && StringUtils.isNotEmpty(houseType.getHcode())){
			houseType=houseTypeService.get(houseType.getHcode());
		}
		return "load";
	}
	public HouseType getHouseType() {
		return houseType;
	}
	public void setHouseType(HouseType houseType) {
		this.houseType = houseType;
	}
	public List<HouseType> getHouseTypes() {
		return houseTypes;
	}
	public void setHouseTypes(List<HouseType> houseTypes) {
		this.houseTypes = houseTypes;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
}
